package dto

import (
	"miao/models"
	"time"
)

type RoleDto struct {
	Id         string     `gorm:"column:primaryKey;id" json:"Id"`       //type:int64        comment:主键        version:2025-07-09 21:34
	RoleName   string     `gorm:"column:role_name" json:"roleName"`     //type:string       comment:角色名称    version:2025-07-09 21:34
	RolePower  string     `gorm:"column:role_power" json:"rolePower"`   //type:string       comment:角色权限    version:2025-07-09 21:34
	TenantId   int64      `gorm:"column:tenant_id" json:"tenantId"`     //type:int64        comment:租户id      version:2025-07-09 21:34
	DelFlag    int32      `gorm:"column:del_flag" json:"delFlag"`       //type:int32        comment:逻辑删除    version:2025-07-09 21:34
	Creator    int32      `gorm:"column:creator" json:"creator"`        //type:int32        comment:创建人      version:2025-07-09 21:34
	CreateDate *time.Time `gorm:"column:create_date" json:"createDate"` //type:*time.Time   comment:创建时间    version:2025-07-09 21:34
	Updater    int64      `gorm:"column:updater" json:"updater"`        //type:int64        comment:更新人      version:2025-07-09 21:34
	UpdateDate *time.Time `gorm:"column:update_date" json:"updateDate"` //type:*time.Time   comment:更新时间    version:2025-07-09 21:34
}

func ToList(roles []models.RoleBase) []RoleDto {
	var result []RoleDto
	for _, role := range roles {
		dto := ToDto(&role)
		result = append(result, dto)
	}
	return result
}

func ToStringList(roles []models.RoleBase) []string {
	var result []string
	for _, role := range roles {
		roleName := role.RoleName
		result = append(result, roleName)
	}
	return result
}

func ToDto(role *models.RoleBase) RoleDto {
	return RoleDto{
		Id:         role.Id,
		RoleName:   role.RoleName,
		RolePower:  role.RolePower,
		TenantId:   role.TenantId,
		DelFlag:    role.DelFlag,
		Creator:    role.Creator,
		CreateDate: role.CreateDate,
		Updater:    role.Updater,
		UpdateDate: role.UpdateDate,
	}
}
